// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class RDR_RDR : AbstractMessage
    {
		/// Constructor
		public RDR_RDR() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "RDR", TriggerEvent = "RDR" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("MSA",2)]
  	    [HL7Field(HL7Version.v23, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v231, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v24, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v251, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v26, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v24, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v25, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v251, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v26, 2, HL7Repeat.False, HL7Required.True,"MSA")]
  	    [HL7Field(HL7Version.v27, 2, HL7Repeat.False, HL7Required.True,"MSA")]
	    public MSA MSA {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ERR",4)]
  	    [HL7Field(HL7Version.v23, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v231, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v24, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v251, 3, HL7Repeat.True, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v26, 3, HL7Repeat.True, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v24, 4, HL7Repeat.False, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v25, 3, HL7Repeat.True, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v251, 3, HL7Repeat.True, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v26, 3, HL7Repeat.True, HL7Required.False,"ERR")]
  	    [HL7Field(HL7Version.v27, 3, HL7Repeat.True, HL7Required.False,"ERR")]
	    public ERR[] ERR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("DEFINITION",6)]
  	    [HL7Field(HL7Version.v23, 6, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v231, 6, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v24, 6, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v251, 5, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v24, 6, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v25, 5, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v251, 5, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v26, 6, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
  	    [HL7Field(HL7Version.v27, 6, HL7Repeat.True, HL7Required.True,"DEFINITION_RDR_RDR")]
	    public DEFINITION_RDR_RDR[] DEFINITION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("DSC",46)]
  	    [HL7Field(HL7Version.v23, 46, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v231, 46, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v24, 46, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v251, 34, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v26, 35, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v24, 46, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v25, 26, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v251, 26, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v26, 27, HL7Repeat.False, HL7Required.False,"DSC")]
  	    [HL7Field(HL7Version.v27, 35, HL7Repeat.False, HL7Required.False,"DSC")]
	    public DSC DSC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("SFT",4)]
  	    [HL7Field(HL7Version.v251, 4, HL7Repeat.False, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v26, 4, HL7Repeat.False, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v25, 4, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v251, 4, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v26, 4, HL7Repeat.True, HL7Required.False,"SFT")]
  	    [HL7Field(HL7Version.v27, 4, HL7Repeat.False, HL7Required.False,"SFT")]
	    public SFT[] SFT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UAC",5)]
  	    [HL7Field(HL7Version.v26, 5, HL7Repeat.False, HL7Required.False,"UAC")]
  	    [HL7Field(HL7Version.v26, 5, HL7Repeat.False, HL7Required.False,"UAC")]
  	    [HL7Field(HL7Version.v27, 5, HL7Repeat.False, HL7Required.False,"UAC")]
	    public UAC UAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("QRD",7)]
  	    [HL7Field(HL7Version.v26, 7, HL7Repeat.False, HL7Required.True,"QRD")]
	    public QRD QRD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("QRF",8)]
  	    [HL7Field(HL7Version.v26, 8, HL7Repeat.False, HL7Required.False,"QRF")]
	    public QRF QRF {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PID",10)]
  	    [HL7Field(HL7Version.v26, 10, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NTE",11)]
  	    [HL7Field(HL7Version.v26, 11, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("ORC",14)]
  	    [HL7Field(HL7Version.v26, 14, HL7Repeat.False, HL7Required.True,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("TQ1",16)]
  	    [HL7Field(HL7Version.v26, 16, HL7Repeat.False, HL7Required.True,"TQ1")]
  	    [HL7Field(HL7Version.v26, 22, HL7Repeat.False, HL7Required.True,"TQ1")]
	    public TQ1 TQ1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("TQ2",17)]
  	    [HL7Field(HL7Version.v26, 17, HL7Repeat.True, HL7Required.False,"TQ2")]
  	    [HL7Field(HL7Version.v26, 23, HL7Repeat.True, HL7Required.False,"TQ2")]
	    public TQ2[] TQ2 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RXE",20)]
  	    [HL7Field(HL7Version.v26, 20, HL7Repeat.False, HL7Required.True,"RXE")]
	    public RXE RXE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RXR",25)]
  	    [HL7Field(HL7Version.v26, 25, HL7Repeat.True, HL7Required.True,"RXR")]
  	    [HL7Field(HL7Version.v26, 30, HL7Repeat.True, HL7Required.True,"RXR")]
	    public RXR[] RXR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RXC",26)]
  	    [HL7Field(HL7Version.v26, 26, HL7Repeat.True, HL7Required.False,"RXC")]
  	    [HL7Field(HL7Version.v26, 31, HL7Repeat.True, HL7Required.False,"RXC")]
	    public RXC[] RXC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RXD",29)]
  	    [HL7Field(HL7Version.v26, 29, HL7Repeat.False, HL7Required.True,"RXD")]
	    public RXD RXD {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v23 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		}
		if (HL7Version.v231 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		}
		if (HL7Version.v24 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		}
		if (HL7Version.v251 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v26 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		 QRD = PopSegmentParseAndCheckRequired<QRD>(availableData, options, "QRD");
		 QRF = PopSegmentParseAndCheckRequired<QRF>(availableData, options, "QRF");
		 PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
		 NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
		 ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
		 TQ1 = PopSegmentParseAndCheckRequired<TQ1>(availableData, options, "TQ1");
		 TQ2 = PopSegmentParseAndCheckRequiredArray<TQ2>(availableData, options, "TQ2");
		 RXE = PopSegmentParseAndCheckRequired<RXE>(availableData, options, "RXE");
		 RXR = PopSegmentParseAndCheckRequiredArray<RXR>(availableData, options, "RXR");
		 RXC = PopSegmentParseAndCheckRequiredArray<RXC>(availableData, options, "RXC");
		 RXD = PopSegmentParseAndCheckRequired<RXD>(availableData, options, "RXD");
		}
		if (HL7Version.v25 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		}
		if (HL7Version.v27 == options.Version) {
		 MSA = PopSegmentParseAndCheckRequired<MSA>(availableData, options, "MSA");
		 ERR = PopSegmentParseAndCheckRequiredArray<ERR>(availableData, options, "ERR");
		 DEFINITION = ProcessGroupArray<DEFINITION_RDR_RDR>(availableData, options, "DEFINITION");
		 DSC = PopSegmentParseAndCheckRequired<DSC>(availableData, options, "DSC");
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "RDR_RDR";
			}
        }

        static RDR_RDR() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(RDR_RDR));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (MSA != null) {
				segmentData.Add(MSA.GetER7(options));
			}
			if (ERR != null && ERR.Length > 0) {
				for (int i = 0; i < ERR.Length; i++) {
					segmentData.Add(ERR[i].GetER7(options));
				}
			}
			if (DEFINITION != null && DEFINITION.Length > 0) {
				for (int i = 0; i < DEFINITION.Length; i++) {
					segmentData.Add(DEFINITION[i].GetER7(options));
				}
			}
			if (DSC != null) {
				segmentData.Add(DSC.GetER7(options));
			}
			if (SFT != null && SFT.Length > 0) {
				for (int i = 0; i < SFT.Length; i++) {
					segmentData.Add(SFT[i].GetER7(options));
				}
			}
			if (UAC != null) {
				segmentData.Add(UAC.GetER7(options));
			}
			if (QRD != null) {
				segmentData.Add(QRD.GetER7(options));
			}
			if (QRF != null) {
				segmentData.Add(QRF.GetER7(options));
			}
			if (PID != null) {
				segmentData.Add(PID.GetER7(options));
			}
			if (NTE != null && NTE.Length > 0) {
				for (int i = 0; i < NTE.Length; i++) {
					segmentData.Add(NTE[i].GetER7(options));
				}
			}
			if (ORC != null) {
				segmentData.Add(ORC.GetER7(options));
			}
			if (TQ1 != null) {
				segmentData.Add(TQ1.GetER7(options));
			}
			if (TQ2 != null && TQ2.Length > 0) {
				for (int i = 0; i < TQ2.Length; i++) {
					segmentData.Add(TQ2[i].GetER7(options));
				}
			}
			if (RXE != null) {
				segmentData.Add(RXE.GetER7(options));
			}
			if (RXR != null && RXR.Length > 0) {
				for (int i = 0; i < RXR.Length; i++) {
					segmentData.Add(RXR[i].GetER7(options));
				}
			}
			if (RXC != null && RXC.Length > 0) {
				for (int i = 0; i < RXC.Length; i++) {
					segmentData.Add(RXC[i].GetER7(options));
				}
			}
			if (RXD != null) {
				segmentData.Add(RXD.GetER7(options));
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

